<?php
define("DIS_APP_NAME", 'dis');

class DistApi extends BaseModule
{
	private $queue;
	public function __construct()
	{
	}
	
	public function distributeAction($class, $func, $params)
	{
		if(defined("DIS_CALL"))
		{
			return true;
		}
		
		$local = C('LOCAL_IDC_NAME');
		$conf = C('IDC_DIS_CONF');
		$pass = array();
		$pass[] = $local;
		$data = array(
						'class' => $class,
						'func' => $func,
						'params' => $params,
						'from' => 'local',
						'source' => $local,
						'pass' => $pass,
						'ttl' => 10,				//最多传递十个结点，终极防止无限包
						'route' => 0,				//路由选择
						'timestamp' => time(),
					);
					
		$q = new DisQueue($conf[$local]['hosts']);
		foreach ($conf[$local]['dest'] as $value)
		{
			$data['dest'] = $value;
			$json = json_encode($data);
			$ret = $q->put(DIS_APP_NAME.'-'.APP_NAME,$json);
			
			if(!$ret)
			{
				//log_error
				echo "dispatch failed";
			}
		}
		
		return true;
		
	}
	
};